<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DiscMaster.Web.Models.Player>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	DiscMaster | MyDetails | <%= Model.UserName %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%= Html.DisplayForModel()%>
    <div style="float: left; width: 360px;">
        <div style="padding-top: 4px; clear: both;">
            <img alt="edit" src="/Image.ashx?src=/Content/Media/Icons/24x24/edit.png&width=18" style="vertical-align: middle;" />
            <%=Html.ActionLink("Edit your details", "Edit", new { id=Model.UserId }) %> | 
            <img alt="add" src="/Image.ashx?src=/Content/Media/Icons/24x24/add.png&width=18" style="vertical-align: middle;" />
            <%=Html.ActionLink("Add friend", "MakeFriend", new { id=Model.UserId }) %> | 
            <img alt="add" src="/Image.ashx?src=/Content/Media/Icons/24x24/add.png&width=18" style="vertical-align: middle;" />
            <%=Html.ActionLink("Register match", "Create", "Matches", new { area = "Matches" }, null)%>
            <br /><br />
        </div>
<%                       
	System.Web.UI.DataVisualization.Charting.Chart Chart1 = new System.Web.UI.DataVisualization.Charting.Chart();
    Chart1.Width = 350;
    Chart1.Height = 296;
    Chart1.RenderType = RenderType.ImageTag;
    Chart1.ImageLocation = "..\\..\\TempImages\\ChartPic_#SEQ(200,30)";

    Chart1.Palette = ChartColorPalette.BrightPastel;

    Title t = new Title("Trend in results", Docking.Top, new System.Drawing.Font("Trebuchet MS", 14, System.Drawing.FontStyle.Bold), System.Drawing.Color.FromArgb(26, 59, 105));
    Chart1.Titles.Add(t);

    DiscMaster.Web.Models.DiscMasterDataContext dc = new DiscMaster.Web.Models.DiscMasterDataContext();
    Chart1.ChartAreas.Add("Series 1");
    Chart1.ChartAreas[0].AxisY.Title = "Number of throws";
    //Chart1.ChartAreas[0].AxisY.Maximum = dc.Matches.GetByPlayer(Model.UserId.ToString()).Max(m => m.Scores(Model.UserId.ToString()).Sum(mr => mr.result));
    //Chart1.ChartAreas[0].AxisY.Minimum = dc.Matches.GetByPlayer(Model.UserId.ToString()).Min(m => m.Scores(Model.UserId.ToString()).Sum(mr => mr.result));
    //Chart1.ChartAreas[0].AxisX.Title = "Matches";
    Chart1.ChartAreas[0].AxisX.LabelStyle.Angle = 30;
    
    System.Web.UI.DataVisualization.Charting.Series ser;

    ser = new System.Web.UI.DataVisualization.Charting.Series("throws");
    ser.MarkerSize = 10;
    ser.IsValueShownAsLabel = true;
    ser.MarkerStyle = MarkerStyle.Circle;
    ser.ChartType = SeriesChartType.Column;
    ser.BorderWidth = 3;

    System.Web.UI.DataVisualization.Charting.Series ser2 = new System.Web.UI.DataVisualization.Charting.Series("par");
    ser2.MarkerSize = 10;
    ser2.IsValueShownAsLabel = true;
    //ser2.MarkerStyle = MarkerStyle.Circle;
    ser2.ChartType = SeriesChartType.Column;
    ser2.BorderWidth = 3;

    foreach (var match in new DiscMaster.Web.Models.DiscMasterRepository().FindAllMatches(Model.UserId).Take(3))
    {
        foreach (var res in match.MatchResults.Where(p=>p.playerid.Equals(Model.UserId)).GroupBy(s=>s.matchid))
        {
            //ser.Label = res.Sum(r => r.result).ToString();
            ser.Points.AddXY(res.First().Match.name, res.Sum(r => r.result));
            //ser2.Label = res.Sum(r => r.Hole.par).ToString();
            ser2.Points.AddXY("par", res.Sum(r => r.Hole.par));
        }
    }
    Chart1.Series.Add(ser);
    Chart1.Series.Add(ser2);

    Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
	Chart1.BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
    Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
	Chart1.BorderWidth = 2;
	
    Chart1.Legends.Add("Legend1");
    Chart1.Legends[0].LegendStyle = LegendStyle.Row;
    Chart1.Legends[0].Docking = Docking.Bottom;
    Chart1.Legends[0].Position.Auto = true;
	
	// Render chart control
	Chart1.Page = this.Page;
	HtmlTextWriter writer = new HtmlTextWriter(Page.Response.Output);
	Chart1.RenderControl(writer);

 %>
 <p>
    <em>the 'trend in results' graph shows the last three (or less) matches played</em>
 </p>
</div>
    <div style="vertical-align: top; padding-left: 40px; width: 200px; float: left;">
        <h1>Friends</h1>
        <br />
        <% foreach (var friend in Model.Friends)
           {
               %>
                <a href='/players/Players/Details/<%= friend.friendid%>'>
                    <img border="0" alt="friend" src='<%= String.Format("/Image.ashx?src=/Content/Media/Images/Players/{0}&width=40&height=40", friend.Player.PlayerDetail.profilepicture.IfEmptyThen("noprofilepicture.png")) %>' style="float: left; padding-right: 4px; padding-bottom: 4px;" title='<%= friend.Player.UserName %>' />
               </a>
               <%
           } %>
           <div style="clear: both;">
               </div>
    </div>
    <div style="float: right; width: 210px; clear: right;">
        <h3>3 most recent matches</h3>
	    <% foreach (var match in Model.Matches.OrderByDescending(m=>m.matchdate).Take(3))
        {
            %>
                <%= match.matchdate.ToString("MM-dd") %>: <strong><%= Html.ActionLink(match.name,"Details","Matches", new {area="Matches",id=match.matchid}, null) %></strong>
                <br /><%= match.MatchPlayers.Count %> players at <%= match.Course.name %>
                <br /><br />
            <% 
        } %>

        <h3>Clubs</h3>
        <% if (Model.ClubMembers.Count == 0)
           {
                %>
                not a member of any clubs..
                <%} %>
	    <% foreach (var club in Model.Clubs)
        {
            %>
                <%= Html.ActionLink(club.name, "Details", "Clubs", new { area = "clubs", id = club.clubid }, null)%>
                <br /><br />
            <% 
        } %>
    </div>
    <br style="clear: both;" />
    <div style="padding-top: 4px; clear: both;">
    <% switch (Model.PlayerDetail.gender.ToString())
	{
           case null:
               %>
                <img alt="publicprofile" src="/Image.ashx?src=/Content/Media/Icons/24x24/friends.png&width=18" style="vertical-align: middle;" />
                &nbsp;
               <%
               break;
           case "0":
               %>
                <img alt="publicprofile" src="/Image.ashx?src=/Content/Media/Icons/24x24/male.png&width=18" style="vertical-align: middle;" />
                &nbsp;
               <%
               break;
           case "1":
               %>
                <img alt="publicprofile" src="/Image.ashx?src=/Content/Media/Icons/24x24/female.png&width=18" style="vertical-align: middle;" />
                &nbsp;
               <%
               break;
		default:
             break;
	} %>
        public profile:
        <%= Html.ActionLink(Url.Action("Details", "Players", new {area="Players", id=Model.UserName}, "http"), "Details", "Players", new {area="Players", id=Model.UserName}, null) %>
    </div>
</asp:Content>

